package cn.itcast.controller;


import cn.itcast.domain.SubArchive;
import cn.itcast.service.SubArchiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
public class SubArchiveController {

    @Autowired
    private SubArchiveService subArchiveService;


   @RequestMapping("/sub_save")
    public  String save(SubArchive subArchive){
       subArchiveService.save(subArchive);
       return "redirect:/pages/base/sub_area.html";

    }



    @RequestMapping("/sub_pageQuery")
    @ResponseBody
    public Map pageQuery(int page, int rows ) {

        Page<SubArchive> pageResult =  subArchiveService.pageQuery(page, rows);
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("total", pageResult.getTotalElements());
        result.put("rows", pageResult.getContent());

        return result;
    }


}
